﻿using Aop.Api;
using Aop.Api.Request;
using Aop.Api.Response;
using SKIT.FlurlHttpClient.Wechat.TenpayV3;
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public class ThirdPaymentHelper
    {
        #region 第三方支付接口
        //第三方微信对接用法，参数全是乱填，需要根据特定东西来传
        public async Task WechatApiAsync()
        {
            WechatTenpayClient wechatTenpayClient = new WechatTenpayClient(new WechatTenpayClientOptions()
            {
                MerchantId = DateTimeOffset.Now.ToUnixTimeSeconds().ToString(),
                MerchantCertificateSerialNumber = Guid.NewGuid().ToString("N"),
                MerchantCertificatePrivateKey = "",
                MerchantV3Secret = Guid.NewGuid().ToString("N"),
                PlatformCertificateManager = null,
                AutoEncryptRequestSensitiveProperty = true
            });
            var request = new CreateApplyForSubjectApplymentRequest()
            {
                Contact = new CreateApplyForSubjectApplymentRequest.Types.Contact()
                {
                    ContactName = "",
                    IdNumber = ""
                },
                Identification = new CreateApplyForSubjectApplymentRequest.Types.Identification()
                {
                    IdName = "",
                    IdNumber = "",
                    IdAddress = ""
                },
                UBOList = new List<CreateApplyForSubjectApplymentRequest.Types.UBO>()
                    {
                        new CreateApplyForSubjectApplymentRequest.Types.UBO()
                        {
                            IdName = "",
                            IdNumber = "",
                            IdAddress = ""
                        }
                }
            };
            var response = await wechatTenpayClient.ExecuteCreateApplyForSubjectApplymentAsync(request);
        }

        //支付宝官方SDK，各接口请看 https://opendocs.alipay.com/mini/api?pathHash=5b4d0c83 文档
        public void AliPayApi()
        {
            IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", "APPID", "APP_PRIVATE_KEY", "json", "1.0", "RSA2", "ALIPAY_PUBLIC_KEY", "CHARSET", false);
            //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如：alipay.open.public.template.message.industry.modify 
            AlipayOpenPublicTemplateMessageIndustryModifyRequest request = new AlipayOpenPublicTemplateMessageIndustryModifyRequest();
            //SDK已经封装掉了公共参数，这里只需要传入业务参数
            //此次只是参数展示，未进行字符串转义，实际情况下请转义
            request.BizContent = "{" +
            "    \"primary_industry_name\":\"IT科技/IT软件与服务\"," +
            "    \"primary_industry_code\":\"10001/20102\"," +
            "    \"secondary_industry_code\":\"10001/20102\"," +
            "    \"secondary_industry_name\":\"IT科技/IT软件与服务\"" +
            "  }";
            AlipayOpenPublicTemplateMessageIndustryModifyResponse response = client.Execute(request);
            if (!response.IsError)
            {
                //调用成功
            }
            else
            {
                Console.WriteLine("调用失败");
            }
            //调用成功，则处理业务逻辑
        }

        #endregion
    }
}
